<!DOCTYPE html>
<html lang="en">

<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<meta charset="utf-8">
	<title></title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
	<meta name="description" content="">
	<meta name="author" content="">
	<!-- STYLESHEETS -->
	<!--[if lt IE 9]><script src="../../js/flot/excanvas.min.js"></script><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
	<link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css">
	<link rel="stylesheet" type="text/css" href="../../css/themes/default.css" id="skin-switcher">
	<link rel="stylesheet" type="text/css" href="../../css/responsive.css">

	<link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
	<!-- file-input -->
	<link rel="stylesheet" type="text/css" href="../../js/file-input/fileinput.css" />
	<!-- SELECT2 -->
	<link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css" />
	<!-- UNIFORM -->
	<link rel="stylesheet" type="text/css" href="../../js/uniform/css/uniform.default.min.css" />
	<!-- datatable -->
	<link rel="stylesheet" href="../../js/datatables/datatable.css">
	<!-- WIZARD -->
	<link rel="stylesheet" type="text/css" href="../../js/bootstrap-wizard/wizard.css" />
	<link rel="stylesheet" href="../../js/datepicker/datepicker.css">
	<!-- FONTS
	<link href='http://fonts.useso.com/css?family=Open+Sans:300,400,600,700' rel='stylesheet' type='text/css'>
-->

</head>

<body>
	<header class="navbar clearfix" id="header">
	</header>
	<!-- PAGE -->
	<section id="page">
		<!-- SIDEBAR -->
		<div id="sidebar" class="sidebar">
			<div class="sidebar-menu nav-collapse">
				<!-- SIDEBAR MENU -->
				<ul>

				</ul>
				<!-- /SIDEBAR MENU -->
			</div>
		</div>
		<!-- /SIDEBAR -->
		<div id="main-content">
			<div class="container">
				<div class="row">
					<div id="content" class="col-lg-12">
						<!-- PAGE HEADER-->
						<div class="row">
							<div class="col-sm-12">
								<div class="page-header">
									<!-- STYLER -->

									<!-- /STYLER -->
									<!-- BREADCRUMBS -->
									<ul class="breadcrumb">
										<li>
											<i class="fa fa-home"></i>
											<a href="index.html">首页</a>
										</li>
										<li>
											<a href="#">供应商管理</a>
										</li>
										<li>新建供应商</li>
									</ul>
									<!-- /BREADCRUMBS -->

								</div>
							</div>
						</div>
						<!-- /PAGE HEADER -->
						<!-- SAMPLE -->
						<form id="form_coupon">
							<div class="row col-md-12">
								<div class="col-md-3" style="width: 25%;margin:20px 0;">
									<div class="" style="text-align: center;font-size:24px;">基本信息</div>
								</div>
								<div class="col-md-9">
									<div class="box border primary">
										<div class="row mrg-bt10-right" style="margin:5px 0;height: 40px;">
											<label class="control-label col-md-3">
												<span class="required">*</span>品牌商简称：</label>
											<div class="col-md-8 inline">
												<input type="text" class="form-control width-50" name="supplierName" placeholder="品牌商简称" maxlength="50" />

												<span class="error-span"></span>

											</div>
										</div>

										<div class="row mrg-bt10-right" style="margin:5px 0;height: 40px;">
											<label class="control-label col-md-3">
												<span class="required">*</span>品牌商类型：</label>
											<div class="col-md-8 inline">
												<select name="supplierType" id="select_supplierType">
													<option value='OnLine'>线上</option>
													<option value='OffLine'>线下</option>
												</select>
											</div>
										</div>
										<div class="row mrg-bt10-right" style="margin:5px 0;height: 40px;">
											<label class="control-label col-md-3">
												<span class="required">*</span>发货方式：</label>
											<div class="col-md-8 inline">
												<select name="sendType" id="select_sendType">
												<option value='-1'>选择发货 方式</option>
													<option value='SupplierSend'>商家发货</option>
													<option value='YiigooSend'>壹果代发货</option>
													<option value='StockSend'>仓库发货</option>
												</select>
												<span>壹果代发货:商品进入科捷仓库，财务统计属于商家，仓库发货：壹果自有商品</span>
											</div>
										</div>
										<div class="row mrg-bt10-right" style="margin:5px 0;height: 40px;">
											<label class="control-label col-md-3">
												<span class="required">*</span>品牌商用户名：</label>
											<div class="col-md-8 inline">
												<input type="text" class="form-control width-50" name="loginName" placeholder="系统登录的用户名" maxlength="50" />
												<input type="hidden" name="id" />
												<span class="error-span"></span>

											</div>
										</div>
										<div class="row mrg-bt10-right" style="margin:5px 0;height: 40px;">
											<label class="control-label col-md-3">
												<span class="required">*</span>登录密码：</label>
											<div class="col-md-8 inline">
												<input type="text" class="form-control width-50" name="loginPassword" placeholder="登录密码" maxlength="50" />

												<span class="error-span"></span>
											</div>
                    </div>
                    <!-- 取消logo -->
										<!-- <div class="form-group mrg-bt10-right" style="margin:5px 0;height: 100px;">
											<label class="control-label col-md-3" style="line-height:34px;">
												<span class="required">*</span>LOGO：</label>
											<div class="col-md-8" id="logo">
												<div hidden-image></div>
												<div class="fileinput fileinput-new" data-provides="fileinput" style="display: block;">
													<div class="image_preview_list" style="float:left;" id="imgs">
														<div class="fileinput-preview thumbnail image_preview_default" data-trigger="fileinput" style="width: 120px; height: 90px;"></div>
													</div>
													<div style="float:left; margin-left:5px; padding-top:23px;" class="addnewimg" id="f_span">
														<span class="btn btn-default btn-file" id="fir">
															<span class="fileinput-new" id="logo_upload">上传图片</span>
															<span class="fileinput-exists">Change</span>
															<input type="file" name="uploadFile" upload-file="imageUrlProduct" />
														</span>
														<a href="#" class="btn btn-default fileinput-exists" data-dismiss="fileinput">Remove</a>
													</div>
												</div>
											</div>
                    </div> -->
                    <!-- 取消banner -->
										<!-- <div class="form-group mrg-bt10-right" style="margin:5px 0;height: 100px;">
											<label class="control-label col-md-3" style="line-height:34px;">
												<span class="required">*</span>Banner图：</label>
											<div class="col-md-8" id="banner">
												<div hidden-image></div>
												<div class="fileinput fileinput-new" data-provides="fileinput" style="display: block;">
													<div class="image_preview_list" style="float:left;" id="imgs">
														<div class="fileinput-preview thumbnail image_preview_default" data-trigger="fileinput" style="width: 120px; height: 90px;"></div>
													</div>
													<div style="float:left; margin-left:5px; padding-top:23px;" class="addnewimg" id="f_span">
														<span class="btn btn-default btn-file" id="fir">
															<span class="fileinput-new" id="banner_upload">上传图片</span>
															<span class="fileinput-exists">Change</span>
															<input type="file" name="uploadFile" upload-file="imageUrlProduct">
														</span>
														<a href="#" class="btn btn-default fileinput-exists" data-dismiss="fileinput">Remove</a>
													</div>
												</div>
											</div>
										</div> -->
									</div>
								</div>
							</div>
							<div class="row col-md-12">
								<div class="col-md-3" style="width: 25%;">
									<div class="" style="text-align: center;font-size:24px;">联系方式</div>
								</div>
								<div class="col-md-9">
									<div class="box border primary">
										<div class="row mrg-bt10-right" style="margin:5px 0;">
											<label class="control-label col-md-3">
												<span class="required">*</span>联系人：</label>
											<div class="col-md-8 inline">
												<input type="text" class="form-control width-50" name="linkMan" placeholder="请输入名字" maxlength="50" />

												<span class="error-span"></span>
											</div>
										</div>
										<div class="row mrg-bt10-right" style="margin:5px 0;">
											<label class="control-label col-md-3">邮件：</label>
											<div class="col-md-8 inline">
												<input type="text" class="form-control width-50" name="email" placeholder="请输入邮件" maxlength="50" />

												<span class="error-span"></span>
											</div>
										</div>
										<div class="row mrg-bt10-right" style="margin:5px 0;">
											<label class="control-label col-md-3">
												<span class="required">*</span>电话：</label>
											<div class="col-md-8 inline">
												<input type="text" class="form-control width-50" name="telPhone" placeholder="请输入电话" maxlength="50" />

												<span class="error-span"></span>
											</div>
										</div>
									</div>
								</div>
							</div>
							<div class="row col-md-12">
								<div class="col-md-3" style="width: 25%;">
									<div class="" style="text-align: center;font-size:24px;">结算信息</div>
								</div>
								<div class="col-md-9">
									<div class="box border primary">
										<div class="form-group mrg-bt10-right" style="margin:5px 0;">
											<label class="control-label col-md-3">
												<span class="required">*</span>结算方式：</label>
											<div class="col-md-8 inline">
												<select name="paymentMode" id="select_paymentMode">
													<option value='Commission' selected="selected">按佣金</option>
													<option value='Cost'>按成本</option>
												</select>
											</div>
										</div>
										<div class="row mrg-bt10-right" style="margin:5px 0;">
											<label class="control-label col-md-3">
												<span class="required">*</span>佣金比例：</label>
											<div class="col-md-8 inline">
                        <input type="text" class="form-control width-50" name="commissionRate" placeholder="请输入佣金比例" maxlength="50" />
                        <span>例：0.05</span>
												<span class="error-span"></span>
											</div>
										</div>
										<div class="row mrg-bt10-right" style="margin:5px 0;">
											<label class="control-label col-md-3">
                        <span class="required">*</span>结算周期：
                      </label>
											<div class="col-md-8 inline">
												<select id="select_paymentCycle" style="float: left;margin: 2px 5px 0 0">
                          <option value="month">自然月</option>
                          <option value="date">天&nbsp;&nbsp;&nbsp;&nbsp;</option>
                        </select>
                        <input type="text" class="form-control width-50" name="paymentCycle" placeholder="请输入结算周期" maxlength="50" /> 天(T+n)
												<span class="error-span"></span>
											</div>
										</div>
										<div class="row mrg-bt10-right" style="margin:5px 0;">
											<label class="control-label col-md-3">
												<span class="required">*</span>返利：</label>
											<div class="col-md-8 inline">
												<select name="shareRate" id="select_shareRate" disabled>
                          <option value="0.05">5%</option>
                          <!-- 默认只能是5% -->
													<!-- <option value="0.1">10%</option>
													<option value="0.15">15%</option> -->
												</select>(将直接影响到商品分享返利)
												<span class="error-span"></span>
											</div>
										</div>
									</div>
								</div>
							</div>
							<div class="row col-md-12">
								<div class="col-md-3" style="width: 25%;">
									<div class="" style="text-align: center;font-size:24px;">退货信息</div>
								</div>
								<div class="col-md-9">
									<div class="box border primary">
										<div class="row mrg-bt10-right" style="margin:5px 0;">
											<label class="control-label col-md-3">
												<span class="required">*</span>退货收货人：</label>
											<div class="col-md-8 inline">
												<input type="text" class="form-control width-50" name="returnReceiver" placeholder="请输入退货收货人" maxlength="50" />

												<span class="error-span"></span>
											</div>
										</div>
										<div class="row mrg-bt10-right" style="margin:5px 0;">
											<label class="control-label col-md-3">
												<span class="required">*</span>退货联系电话：</label>
											<div class="col-md-8 inline">
												<input type="text" class="form-control width-50" name="returnTelPhone" placeholder="请输入退货联系电话" maxlength="50" />

												<span class="error-span"></span>
											</div>
										</div>
										<div class="row mrg-bt10-right" style="margin:20px 0;">
											<label class="control-label col-md-3">
												<span class="required">*</span>退货地址：</label>
											<div class="col-md-8 inline">
												<input type="text" class="form-control width-50" name="returnAddress" placeholder="请输入退货地址" maxlength="50" />

												<span class="error-span"></span>
											</div>
										</div>
									</div>
								</div>
							</div>

							<div class="row" style="height: 30px;">
								<div class="col-md-12" style="text-align: center;">
									<div class="box">
										<a class="btn btn-success  bt-submit" style="width: 100px">保存</a>
									</div>
								</div>
							</div>
						</form>
						<!-- /SAMPLE -->

						<div class="footer-tools">
							<span class="go-top">
								<i class="fa fa-chevron-up"></i> Top
							</span>
						</div>
					</div>
					<!-- /CONTENT-->
				</div>
			</div>
		</div>
	</section>
	<!--/PAGE -->
	<!-- JAVASCRIPTS -->
	<!-- Placed at the end of the document so the pages load faster -->
	<!-- JQUERY -->
	<script src="../../js/jquery/jquery-2.0.3.min.js"></script>
	<script src="../../js/common.js"></script>
	<script src="../../js/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js"></script>
	<!-- BOOTSTRAP -->
	<script src="../../bootstrap-dist/js/bootstrap.min.js"></script>
	<!-- SLIMSCROLL -->
	<script type="text/javascript" src="../../js/jQuery-slimScroll-1.3.0/jquery.slimscroll.min.js"></script>
	<script type="text/javascript" src="../../js/jQuery-slimScroll-1.3.0/slimScrollHorizontal.min.js"></script>
	<!-- BLOCK UI -->
	<script type="text/javascript" src="../../js/jQuery-BlockUI/jquery.blockUI.min.js"></script>
	<!--bootbox-->
	<script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
	<!-- AUTOSIZE -->
	<script type="text/javascript" src="../../js/autosize/jquery.autosize.min.js"></script>
	<!-- spinner -->
	<script src="../../js/spinner/spin.js"></script>
	<!-- bootstrap-fileupload -->
	<script type="text/javascript" src="../../js/jquery-upload/js/jquery.iframe-transport.js"></script>
	<script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload.min.js"></script>
	<script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload-process.min.js"></script>
	<script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload-validate.min.js"></script>
	<!-- INPUT MASK -->
	<script type="text/javascript" src="../../js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>
	<!-- SELECT2 -->
	<script type="text/javascript" src="../../js/select2/select2.min.js"></script>
	<!-- UNIFORM -->
	<script type="text/javascript" src="../../js/uniform/jquery.uniform.min.js"></script>
	<!-- WIZARD -->
	<script src="../../js/bootstrap-wizard/jquery.bootstrap.wizard.min.js"></script>
	<!-- WIZARD -->
	<script src="../../js/jquery-validate/jquery.validate.min.js"></script>
	<script src="../../js/jquery-validate/additional-methods.min.js"></script>
	<script src="../../js/bootstrap-wizard/form-wizard.js"></script>
	<!-- NESTABLE LISTS -->
	<script type="text/javascript" src="../../js/nestable/jquery.nestable.min.js"></script>
	<!-- COOKIE -->
	<script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
	<!-- CUSTOM SCRIPT -->
	<script src="../../js/script.js"></script>
	<script src="../../js/Sortable.min.js"></script>
	<script>
		var AddCoupon = function () {
			var id = null, flag;
			var wizform = $('#form_coupon');
			var supplierid = $.getUrlParam('id');//判断是否有id  有id编辑  没id新增
			var flag = $.getUrlParam('flag');
			var img = {};


			//初始化验证框架
			var formValiInit = function () {
				wizform.validate({
					doNotHideMessage: true,//不要隐藏信息
					errorClass: 'error-span',
					errorElement: 'span',
					rules: {//返回元素的验证规则
						supplierName: { //品牌商简称
							required: true
						},
						loginName: {//品牌商用户名
							required: true
						},
						loginPassword: {//品牌商密码
							required: true
						},
						// logo: {//logo
						// 	required: true
						// },
						// banner: {//Banner图
						// 	required: true
						// },
						telPhone: {//联系电话
							required: true
						},
						commissionRate: {//佣金比例
							required: true
						},
						paymentCycle: {//结算周期
							required: true
						},
						returnTelPhone: { //退货联系电话
							required: true
						},
						returnReceiver: {//退货收货人
							required: true
						},
						returnAddress: {//退货地址
							required: true
						}
					},
					highlight: function (element) {
						$(element)
							.closest('.row').removeClass('has-success').addClass('has-error');
					},
					unhighlight: function (element) {
						$(element)
							.closest('.row').removeClass('has-error');
					},
					success: function (label) {
						if (label.attr("for") == "gender") {
							label.closest('.row').removeClass('has-error').addClass('has-success');
							label.remove();
						} else {
							label.addClass('valid')
								.closest('.row').removeClass('has-error').addClass('has-success');
						}
					}
				});
			};

			//新增供应链信息
			var saveSupplier = function () {
				if (wizform.valid() == false) return false;//valid功能函数，回传true/false，是否验证通过
               $("[name=paymentCycle]").attr("disabled",false);
               $("[name=shareRate]").attr("disabled",false);
				var mainJson = $("#form_coupon").serializeObject();
				var json = JSON.stringify(mainJson);
				if($("#select_sendType").val()=="-1")
				{
					$.alert("请选择发货方式");
					return false;
				}
				if($("[name=loginPassword]").val().length<8)
				{
					$.alert("密码至少8位");
					return false;
				}
				$.blockUI();
				$.ajax({
					type: "post",
					url: App.getContextPath() + "admin/store/saveSupplier.do",
					data: $.param({ supplier: json }),//参数名字
					async: true,
					success: function (result) {
						$.unblockUI();
						if (result.type == "error") {
							$.alert(result.extra);
						} else {

							window.location.href = "supply_list.html";
						}
					},
          error: function (error) { 
            $.unblockUI();
			if ($('#select_paymentCycle').val() == 'month') {
				$("[name=paymentCycle]").attr("disabled",true);
			}
			$("[name=shareRate]").attr("disabled",true);
          }
				});
			};

			//根据id获取供应链信息
			var getSupplier = function () {
				$.ajax({
					type: "get",
					url: App.getContextPath() + "admin/store/getSupplier.do",
					data: { id: supplierid },
					async: true,
					success: function (result) {
						$("[name=supplierName]").val(result.supplierName);
						$("#select_supplierType").select2("val", result.supplierType);
						$("[name=loginName]").val(result.loginName);
						$("[name=loginName]").attr('readonly', 'readonly');
						$("[name=loginPassword]").val(result.loginPassword);
						$("[name=logo]").val(result.logo);
						$("#logo").find("[hidden-image]").append("<input type='hidden' name='logo' value='" + result.logo + "' />");
						$("#logo").find(".image_preview_default").html("<img src='" + result.logo + "' />");
						$("[name=banner]").val(result.banner);
						$("#banner").find("[hidden-image]").append("<input type='hidden' name='banner' value='" + result.banner + "' />");
						$("#banner").find(".image_preview_default").html("<img src='" + result.banner + "' />");
						$("[name=telPhone]").val(result.telPhone);
						$("[name=email]").val(result.email);
						$("[name=linkMan]").val(result.linkMan);
						$("#select_paymentMode").select2("val", result.paymentMode);
						$("[name=commissionRate]").val(result.commissionRate);
						$("#select_sendType").select2("val",result.sendType);
						
            var paymentCycle = result.paymentCycle,
                type = 'month',
                IsDisabled = true;
            // 如果结算日期为30天 下拉框为自然月 禁用输入框
            if ( paymentCycle != 30) {
              type = 'date';
              IsDisabled = false;
            }
            $("#select_paymentCycle").select2('val', type);
            $("[name=paymentCycle]").val(paymentCycle).attr("disabled",IsDisabled);
						$("#select_shareRate").select2("val", result.shareRate);
						$("[name=returnTelPhone]").val(result.returnTelPhone);
						$("[name=returnReceiver]").val(result.returnReceiver);
						$("[name=returnAddress]").val(result.returnAddress);
						$("#select_supplierType").change();
						$("#select_paymentMode").change();
						$("[name=id]").val(result.id);
					}
				});
			}
			// 上传图片
			var fileUpLoad = function () {
				var file = this.files[0];
				var data = new FormData();
				data.append("uploadFile", file);
				var $tr = $(this).parents('.col-md-8');
				$.ajax({
					type: "POST",
					url: App.getContextPath() + "admin/file/uploadFile.do",
					data: data,
					async: false,
					contentType: false,
					processData: false,
					success: function (result) {
						$tr.find("[hidden-image]").append("<input type='hidden' name='" + $tr.attr('id') + "' value='" + result.fileUrl + "' />");
						$tr.find(".image_preview_default").html("<img src='" + result.fileUrl + "' />");
					},
					error: function () {
						$.alert("图片上传失败！");
					}
				});
			};
			return {
				init: function () {
					formValiInit();
					App.init();
					$(".bt-submit").click(saveSupplier);
					$("#select_supplierType").select2();
					$("#select_paymentMode").select2();
					$("#select_shareRate").select2();
					$("#select_sendType").select2();
          $("#select_paymentCycle").select2();
					if (supplierid != null) {
						getSupplier();
					}
					//查看状态
					if (flag == "1") {
						$("input").attr("readonly", "true");
						$(".btn").hide();
					}
					$("#select_supplierType").change(function () {
						if ($(this).val() == 'OffLine') {
							$(this).parents(".form-group").nextAll().hide();
							$(this).parents(".row").nextAll(".col-md-12").hide();
						} else {
							$(this).parents(".form-group").nextAll().show();
							$(this).parents(".row").nextAll(".col-md-12").show();
						}
					});
					$("#select_paymentMode").change(function () {
						if ($(this).val() == 'Commission') {
							$(this).parents(".mrg-bt10-right").next().show();
						} else {
							$(this).parents(".mrg-bt10-right").next().hide();
						}
					});
					$("#select_supplierType").change();
					$("#select_paymentMode").change();
					$("[upload-file=imageUrlProduct]").change(fileUpLoad);
          // 结算周期下拉框更改
          $("#select_paymentCycle").change(function(e){
            var type = $(this).val(),
                date = 0,
                IsDisabled = false;
            if (type == 'month') {
              date = 30;
              IsDisabled = true;
            }
            $("[name=paymentCycle]").val(date).attr("disabled",IsDisabled);
          });
          $("#select_paymentCycle").select2('val', 'month');
          $("[name=paymentCycle]").val(30).attr("disabled", true);
				}
			}
		}();
		$(function () {
			$("#header").load("../head.html");
			AddCoupon.init();
		});

	</script>
	<!-- /JAVASCRIPTS -->
</body>

</html>